package com.example.hybridmobiledemo.module.login;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Window;

import com.example.hybridmobiledemo.R;

public class WelcomeActivity extends AppCompatActivity implements Runnable {
    public static SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_welcome);
        //启动延迟线程
        new Thread(this).start();
    }

    @Override
    public void run() {
        /*
         *sp的name值模拟初次使用需要修改
         */

        //停留时间使用Thread.sleep()模拟
        try { Thread.sleep(2000); } catch (Exception e) { }

        // 读取SharedPreferences中需要的数据
        sp = getSharedPreferences("s012", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        /**
         * 如果用户不是第一次使用则直接调转到显示界面,否则调转到引导界面
         */

        int x;
        x = sp.getInt("s012",1); //获取记录启动次数的值，若获取不到就默认为1
        if (x == 1)
        {
            //首次启动时跳转GuideActivity
            x++;
            editor.putInt("s012",x);
            editor.commit();
            startActivity(new Intent(WelcomeActivity.this, GuideActivity.class));
            WelcomeActivity.this.finish();
        } else {
            //若不是第一次登录就直接跳转MainActivity
            startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
            WelcomeActivity.this.finish();
        }
    }
}